using UnityEngine;

public class RoomSelectButton : MonoBehaviour
{
	public UISprite logoSprite;

	public UISprite ribbonCentre;

	public UISprite ribbonLeft;

	public UISprite ribbonRight;

	public UISprite coinSprite;

	public UILabel feeLabel;

	public UILabel winLabel;

	public UISprite feeCoin;

	public UILabel feeCentered;

	public UILabel winLabelCentered;

	public UILabel roomNameLabel;

	public UILabel influenceLabel;

	private int coinsNeeded;

	public MultiplayerLobbyLayer lobbyLayer;

	private MultiplayerRoomType roomType;

	public GameObject Shop;

	private MultiplayerRooms.RoomInfo info;

	private void Awake()
	{
	}

	private void OnEnable()
	{
	}

	private void OnClick()
	{
		MultiplayerRooms.RoomInfo roomInfo = MultiplayerRooms.instance.FindRoomByType(roomType);
		int num = GGPlayerSettings.instance.walletManager.CurrencyCount(MultiplayerRooms.instance.multiplayerCurrencyType);
		if (roomInfo.room == MultiplayerRoomType.Training)
		{
			TableTennisMainNavigation.instance.multiplayerSelectLayer.Show(roomInfo);
		}
		else if (roomInfo.maxStarRankForEntry > 0 && GGPlayerSettings.instance.Level() > roomInfo.maxStarRankForEntry)
		{
			TableTennisDialog.instance.ShowOk("You are too good for this room!", "This room is for players with level less than " + roomInfo.maxStarRankForEntry + "! Your level is " + GGPlayerSettings.instance.Level() + " you are a pro :) Play in the next room!", "Ok", null);
		}
		else if (num < coinsNeeded)
		{
			TableTennisDialog.instance.ShowNotEnoughCoins(coinsNeeded, MultiplayerRooms.instance.multiplayerCurrencyType);
		}
		else
		{
			lobbyLayer.FindMatch(info);
		}
	}

	public void Init(MultiplayerRooms.RoomInfo info)
	{
		this.info = info;
		coinsNeeded = info.fee;
		roomType = info.room;
		ChangeSprites(info);
		if (string.IsNullOrEmpty(info.overrideFeeMsgOnCard))
		{
			feeLabel.text = "Entry fee: " + GGFormat.FormatPrice(info.fee);
			feeCoin.cachedGameObject.SetActive(true);
			UITools.SetActive(feeLabel, true);
			UITools.SetActive(feeCentered, false);
		}
		else
		{
			feeCentered.text = info.overrideFeeMsgOnCard;
			feeCoin.cachedGameObject.SetActive(false);
			UITools.SetActive(feeLabel, false);
			UITools.SetActive(feeCentered, true);
		}
		if (string.IsNullOrEmpty(info.overrideWinMsgOnCard))
		{
			UITools.ChangeText(winLabel, "Win " + GGFormat.FormatWinnings(info.prize));
			UITools.SetActive(winLabel, true);
			UITools.SetActive(winLabelCentered, false);
			UITools.SetActive(coinSprite, true);
		}
		else
		{
			UITools.ChangeText(winLabelCentered, info.overrideWinMsgOnCard);
			UITools.SetActive(winLabel, false);
			UITools.SetActive(winLabelCentered, true);
			UITools.SetActive(coinSprite, false);
		}
		UITools.ChangeText(roomNameLabel, info.roomName);
		Debug.Log("Influence on skill " + info.roomName + " skill " + info.influenceOfSkill * 100f);
		UITools.ChangeText(influenceLabel, "Influence Skill: " + Mathf.RoundToInt(info.influenceOfSkill * 100f) + "% Equipment: " + Mathf.RoundToInt(MathEx.Avg(info.racketInfluence, info.shoeInfluence) * 100f) + "%");
	}

	private void ChangeSprites(MultiplayerRooms.RoomInfo info)
	{
		UITools.ChangeSprite(logoSprite, info.roomSprite);
		if (info.useRibbonSprite)
		{
			UITools.ChangeSprite(ribbonCentre, "ribbon " + info.ribbonSprite + " 1");
			UITools.ChangeSprite(ribbonLeft, "ribbon " + info.ribbonSprite + " 2");
			UITools.ChangeSprite(ribbonRight, "ribbon " + info.ribbonSprite + " 3");
		}
		UITools.SetColor(ribbonCentre, info.ribbonColor);
		UITools.SetColor(ribbonLeft, info.ribbonColor);
		UITools.SetColor(ribbonRight, info.ribbonColor);
		UITools.ChangeSprite(coinSprite, info.coinSprite);
	}

	private void OnPurchase(bool success)
	{
		NavigationManager.instance.Pop();
		if (success)
		{
			TableTennisMainNavigation tableTennisMainNavigation = NavigationManager.instance as TableTennisMainNavigation;
			if (Shop != null)
			{
				NavigationManager.instance.Push(Shop);
			}
			else if (tableTennisMainNavigation != null)
			{
				tableTennisMainNavigation.PushCurrencyStore();
			}
		}
	}

	public void ShowInfo()
	{
		string text = "- \"Skill Influence\" means how effective attack and defense skill difference over your opponent is\n- \"Equipment Influence\" is how effective your racket and shoes are in this room\n- Entry fee for this room is " + GGFormat.FormatWinnings(info.fee) + " tokens\n- The winner takes " + GGFormat.FormatWinnings(info.prize) + " tokens prize";
		TableTennisDialog.instance.ShowOk("Room Info", text, "Ok", null);
	}
}
